package com.loongxun.playwithyou.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.loongxun.playwithyou.ApiInterface;
import com.loongxun.playwithyou.App;
import com.loongxun.playwithyou.R;
import com.loongxun.playwithyou.bean.Member;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2017/8/25.
 */
public class EvaluateAdapter extends BaseAdapter {

    private Context context;
    public List<Member> list;
    private LayoutInflater inflater;
    private ImageLoader imageLoader = ImageLoader.getInstance();

    public EvaluateAdapter(Context context, List<Member> list){
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<Member> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_evaluate_lists, null);

            holder.iv_item_info_user_img = (ImageView) convertView.findViewById(R.id.iv_item_info_user_img);
            holder.tv_item_info_user_name = (TextView) convertView.findViewById(R.id.tv_item_info_user_name);
            holder.tv_item_info_eval_time = (TextView) convertView.findViewById(R.id.tv_item_info_eval_time);
            holder.tv_item_info_eval = (TextView) convertView.findViewById(R.id.tv_item_info_eval);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Member item = list.get(position);

        if (!item.getMember_img().equals("")) {
            if (item.getMember_img().startsWith("http://wx.qlogo.cn/mmopen")) {
                imageLoader.displayImage(item.getMember_img(), holder.iv_item_info_user_img, App.options);
            }else {
                imageLoader.displayImage(ApiInterface.IMAGES + item.getMember_img(), holder.iv_item_info_user_img, App.options);
            }
        }
        holder.tv_item_info_user_name.setText(item.getMember_name());
        holder.tv_item_info_eval_time.setText(item.getCreateDate());
        holder.tv_item_info_eval.setText(item.getEvaluateInfo());
        return convertView;
    }

    class ViewHolder {
        private ImageView iv_item_info_user_img;
        private TextView tv_item_info_user_name,tv_item_info_eval_time,
                tv_item_info_eval;
        private LinearLayout ll_item_order_list;
    }
}
